package com.vivien.example.springbootdemo.service;

import com.vivien.example.springbootdemo.dao.IGoodsDao;
import com.vivien.example.springbootdemo.pojo.Goods;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class GoodsService {

    @Autowired
    private IGoodsDao dao;

    public List<Goods> getAll(){
        return dao.getAllGoods();
    }

    public Goods getOne(int id) {
        return dao.getGoodById(id);
    }

    @Transactional(propagation = Propagation.REQUIRED)
    public int addOne(Goods goods) {
        //查询、保人、账单、保单
        //dao.addGood(goods);//出错

        //int i=1/0;

        return dao.addGood(goods);
    }
}
